<?php
namespace App\Utility;
class Openssl
{

    protected $iv = '';
    protected $key = '';
    private static $instance = null;

    private function __construct($mode,$key,$iv)
    {

        $this->mode = $mode;
        $this->key = $key;
        $this->iv = $iv;
    }

    public static function getInstance($mode="aes-128-cbc",$key='kf-system',$iv="1234567899876543")
    {
        if(self::$instance === null){
            self::$instance = new self($mode,$key ,$iv);
        }
        return self::$instance;
    }

    public function encrypt($str)
    {
        $enCode = base64_encode(openssl_encrypt($str, $this->mode, $this->key, true, $this->iv));

        return $enCode;
    }

    public function decrypt($str)
    {
        $str = base64_decode($str,true);
        if(!$str){
            return false;
        }
        $str = openssl_decrypt($str, $this->mode,  $this->key, true, $this->iv);
        return $str;
    }
}

?>